package com.edu.exam.entity.curriculum.questionbank;

import com.edu.exam.enums.curriculum.questionbank.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 试题媒体资源实体类
 * 对应数据库表：question_media
 *
 * 管理试题的媒体资源信息，包括音频、视频、动画等。
 * 支持媒体资源的上传、转码、播放和管理。
 * 关联试题、创建人等关键信息，提供试题媒体资源的完整视图。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Comment("试题媒体资源表")
@SQLDelete(sql = "UPDATE question_media SET is_deleted = true, delete_time = CURRENT_TIMESTAMP WHERE id = ?")
@Where(clause = "is_deleted = false")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class QuestionMedia {

    /**
     * 媒体资源唯一标识符
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    
    private Long id;

    /**
     * 试题ID
     */
    @NotNull(message = "试题ID不能为空")
    @Column(name = "question_id", nullable = false)
    private Long questionId;

    /**
     * 媒体资源名称
     */
    @NotBlank(message = "媒体资源名称不能为空")
    @Size(max = 255, message = "媒体资源名称长度不能超过255个字符")
    @Column(name = "media_name", nullable = false, length = 255)
    private String mediaName;

    /**
     * 媒体类型
     */
    @NotNull(message = "媒体类型不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "media_type", nullable = false, length = 20)
    private MediaType mediaType;

    /**
     * 原始文件存储路径
     */
    @NotBlank(message = "原始文件路径不能为空")
    @Size(max = 500, message = "原始文件路径长度不能超过500个字符")
    @Column(name = "original_file_path", nullable = false, length = 500)
    private String originalFilePath;

    /**
     * 处理后文件路径
     */
    @Size(max = 500, message = "处理后文件路径长度不能超过500个字符")
    @Column(name = "processed_file_path", length = 500)
    private String processedFilePath;

    /**
     * 文件原始名称
     */
    @Size(max = 255, message = "文件原始名称长度不能超过255个字符")
    @Column(name = "original_filename", length = 255)
    private String originalFilename;

    /**
     * 文件扩展名
     */
    @Size(max = 20, message = "文件扩展名长度不能超过20个字符")
    @Column(name = "file_extension", length = 20)
    private String fileExtension;

    /**
     * 文件大小（字节）
     */
    @Column(name = "file_size")
    private Long fileSize;

    /**
     * 媒体时长（秒）
     */
    @Column(name = "duration")
    private Integer duration;

    /**
     * 分辨率
     */
    @Size(max = 50, message = "分辨率长度不能超过50个字符")
    @Column(name = "resolution", length = 50)
    private String resolution;

    /**
     * 比特率
     */
    @Column(name = "bitrate")
    private Integer bitrate;

    /**
     * 帧宽率
     */
    @Column(name = "frame_rate")
    private Integer frameRate;

    /**
     * 文件MIME类型
     */
    @Size(max = 100, message = "MIME类型长度不能超过100个字符")
    @Column(name = "mime_type", length = 100)
    private String mimeType;

    /**
     * 编码格式
     */
    @Size(max = 50, message = "编码格式长度不能超过50个字符")
    @Column(name = "encoding_format", length = 50)
    private String encodingFormat;

    /**
     * 媒体状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "media_status", nullable = false, length = 20)
    private MediaStatus mediaStatus;

    /**
     * 转码状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "transcode_status", length = 20)
    private TranscodeStatus transcodeStatus;

    /**
     * 媒体描述
     */
    @Size(max = 1000, message = "媒体描述长度不能超过1000个字符")
    @Column(name = "description", length = 1000)
    private String description;

    /**
     * 缩略图URL
     */
    @Size(max = 500, message = "缩略图URL长度不能超过500个字符")
    @Column(name = "thumbnail_url", length = 500)
    private String thumbnailUrl;

    /**
     * 预览URL
     */
    @Size(max = 500, message = "预览URL长度不能超过500个字符")
    @Column(name = "preview_url", length = 500)
    private String previewUrl;

    /**
     * 播放URL
     */
    @Size(max = 500, message = "播放URL长度不能超过500个字符")
    @Column(name = "play_url", length = 500)
    private String playUrl;

    /**
     * 下载URL
     */
    @Size(max = 500, message = "下载URL长度不能超过500个字符")
    @Column(name = "download_url", length = 500)
    private String downloadUrl;

    /**
     * 是否自动播放
     */
    @Column(name = "auto_play")
    @Builder.Default
    private Boolean autoPlay = false;

    /**
     * 是否循环播放
     */
    @Column(name = "loop_play")
    @Builder.Default
    private Boolean loopPlay = false;

    /**
     * 是否显示控件
     */
    @Column(name = "show_controls")
    @Builder.Default
    private Boolean showControls = true;

    /**
     * 静音播放
     */
    @Column(name = "muted")
    @Builder.Default
    private Boolean muted = false;

    /**
     * 字幕文件路径
     */
    @Size(max = 500, message = "字幕文件路径长度不能超过500个字符")
    @Column(name = "subtitle_path", length = 500)
    private String subtitlePath;

    /**
     * 媒体元数据，JSON格式
     */
    @Column(name = "metadata", columnDefinition = "TEXT")
    private String metadata;

    /**
     * 转码配置，JSON格式
     */
    @Column(name = "transcode_config", columnDefinition = "TEXT")
    private String transcodeConfig;

    /**
     * 转码日志
     */
    @Column(name = "transcode_log", columnDefinition = "TEXT")
    private String transcodeLog;

    /**
     * 处理开始时间
     */
    @Column(name = "process_start_time")
    private LocalDateTime processStartTime;

    /**
     * 处理完成时间
     */
    @Column(name = "process_end_time")
    private LocalDateTime processEndTime;

    /**
     * 错误信息
     */
    @Size(max = 1000, message = "错误信息长度不能超过1000个字符")
    @Column(name = "error_message", length = 1000)
    private String errorMessage;

    /**
     * 记录创建时间
     */
    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 记录最后更新时间
     */
    @UpdateTimestamp
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 乐观锁版本号
     */
    @Version
    @Column(name = "version", nullable = false)
    @Builder.Default
    private Integer version = 0;

    /**
     * 软删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    @Builder.Default
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;


  }